package A_Druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Date;
import java.util.Properties;

/*
*   a.导入jar包
    b.定义配置文件
    c.加载配置文件 -> Properties类
    d.获取数据库连接
    e.获取执行sql对象
    f.执行sql*/
public class DruidDemo {
    public static void main(String[] args) {
        Properties pro = new Properties();
        try {
//            pro.load(DruidDemo.class.getResourceAsStream("druid.properties"));
            //方式二  类加载
            pro.load(DruidDemo.class.getClassLoader().getResourceAsStream("druid.properties"));
            //获取数据库的连接
            DataSource ds = DruidDataSourceFactory.createDataSource(pro);
            Connection conn = ds.getConnection();
            Statement sta = conn.createStatement();
            String sql ="select * from emp";
            sta.executeQuery(sql);


        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}